package com.mydesignpattern.beijing.proxy.dynamic;

import org.junit.jupiter.api.Test;

import java.lang.reflect.Proxy;

/**
 * 代理模式测试类
 */
public class ProxyTest {

    @Test
    public void jdkProxyTest(){
        Person realPerson = new YellowPerson();
        JdkProxyHandler proxyHandler = new JdkProxyHandler(realPerson);
        Person proxyPerson = (Person)proxyHandler.getInstance();

        //所有方法有效
        proxyPerson.say();
        proxyPerson.eat("noodle");
    }

    @Test
    public void cglibProxyTest(){
        Person realPerson = new BlackPerson();
        CGLibProxyHandler proxyHandler = new CGLibProxyHandler();
        Person proxyPerson = (Person) proxyHandler.getInstance(realPerson);

        proxyPerson.say();
        proxyPerson.eat("rice");

    }


}
